package com.das.mechanic_base.utils;

import android.content.Context;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;

import com.das.mechanic_base.R;
import com.das.mechanic_base.base.X3BaseBottomSheetDialog;
import com.umeng.analytics.MobclickAgent;

public class X3BottomDeletePlanDialog extends X3BaseBottomSheetDialog implements View.OnClickListener {

    private TextView tv_cancel;
    private TextView tv_work;
    private TextView tv_other;
    private Button btn_create;
    private TextView tv_service_name;

    private int cause = -1;

    public X3BottomDeletePlanDialog(@NonNull Context context) {
        super(context);
    }

    @Override
    protected boolean getDialogCancel() {
        return false;
    }

    @Override
    protected void initView() {
        tv_cancel = getView(R.id.tv_cancel);
        tv_work = getView(R.id.tv_work);
        tv_other = getView(R.id.tv_other);
        btn_create = getView(R.id.btn_create);
        tv_service_name = getView(R.id.tv_service_name);

        tv_cancel.setOnClickListener(this);
        btn_create.setOnClickListener(this);
        tv_work.setOnClickListener(this);
        tv_other.setOnClickListener(this);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.x3_bottom_delete_plan_dialog;
    }

    public void showServiceName(String serviceName) {
        if (X3StringUtils.isEmpty(serviceName)) {
            tv_service_name.setVisibility(View.GONE);
            return;
        }
        tv_service_name.setVisibility(View.VISIBLE);
        tv_service_name.setText(serviceName);
    }

    @Override
    protected void onStart() {
        super.onStart();
        MobclickAgent.onPageStart("标记删除保养计划弹窗");
    }

    @Override
    protected void onStop() {
        super.onStop();
        MobclickAgent.onPageEnd("标记删除保养计划弹窗");
    }

    @Override
    public void show() {
        super.show();
        reset();
    }

    private void reset() {
        cause = -1;
        tv_other.setBackground(ContextCompat.getDrawable(mContext,R.drawable.x3_alone_add_new_service_item));
        tv_work.setBackground(ContextCompat.getDrawable(mContext,R.drawable.x3_alone_add_new_service_item));
        tv_other.setTextColor(ContextCompat.getColor(mContext,R.color.c333));
        tv_work.setTextColor(ContextCompat.getColor(mContext,R.color.c333));
    }

    @Override
    public void onClick(View v) {
        int id = v.getId();
        if (id == R.id.tv_cancel) {
            dismiss();
        } else if (id == R.id.tv_work) {
            cause = 0;
            tv_work.setBackground(ContextCompat.getDrawable(mContext, R.drawable.x3_delete_plan_select_bg));
            tv_other.setBackground(ContextCompat.getDrawable(mContext, R.drawable.x3_alone_add_new_service_item));
            tv_work.setTextColor(ContextCompat.getColor(mContext, R.color.bg_0077FF));
            tv_other.setTextColor(ContextCompat.getColor(mContext, R.color.c333));
        } else if (id == R.id.tv_other) {
            cause = 1;
            tv_work.setBackground(ContextCompat.getDrawable(mContext, R.drawable.x3_alone_add_new_service_item));
            tv_other.setBackground(ContextCompat.getDrawable(mContext, R.drawable.x3_delete_plan_select_bg));
            tv_other.setTextColor(ContextCompat.getColor(mContext, R.color.bg_0077FF));
            tv_work.setTextColor(ContextCompat.getColor(mContext, R.color.c333));
        } else if (id == R.id.btn_create) {
            if (cause == -1) {
                return;
            }
            if (iOnDeletePlan != null) {
                iOnDeletePlan.iOnDeletePlanAfter(cause);
            }
            dismiss();
        }

    }

    IOnDeletePlan iOnDeletePlan;

    public X3BottomDeletePlanDialog setiOnDeletePlan(IOnDeletePlan iOnDeletePlan) {
        this.iOnDeletePlan = iOnDeletePlan;
        return this;
    }

    public interface IOnDeletePlan {
        /**
         * 删除或者履行保养计划
         * @param cause
         */
        void iOnDeletePlanAfter(int cause);
    }

}
